import Mongo
import Xlrd_

"""
该类是将excle表格内容上传到mongodb数据库中
class ToMongo(a,b,c,d)，a表格地址，b int类型，(表实际索引)，c需要插入的数据库，d，需要插入的数据库集合

方法1  def jsbtomon() 该方法是将结算表导入到数据库中
方法2  def qxdtomon() 该方法是抢修单总表导入到数据库中
"""


class ToMongo:
    def __init__(self, a, b, c, d):  # a表格地址，b int类型，表索引，c数据库名称，d，数据库集合名称
        self.jsbExcel = Xlrd_.Xlrd_(a, b)
        self.sbDbs = Mongo.Mongo(c, d)

    '''方法1'''

    def jsbtomon(self):
        maxNum = self.jsbExcel.rowsNumber()
        print(maxNum)
        for num in range(2, maxNum + 1):
            row = self.jsbExcel.rd(num)
            print(row)
            ss = {
                "_id": row[0],
                "guige": row[3],
                "neirong": row[1],
                "shuoming": row[2],
                "danwei": row[4],
                "jiage": row[5],
                "beizhu": row[6]
            }
            print(ss)
            self.sbDbs.insertdict(ss)

    '''方法2'''

    def qxdtomon(self):
        maxNum = self.jsbExcel.rowsNumber()
        for num in range(2, maxNum + 1):
            row = self.jsbExcel.rd(num)
            print(row)
            ss = {
                "_id": row[0],
                "code": row[1],
                "pianqu": row[2],
                "leixing": row[3],
                "dizhi": row[4],
                "qiangxiuren": row[5],
                "shijian": row[6],
                "neirong": row[7],
                "sumb": row[8]
            }
            print(ss)

            self.sbDbs.insertdict(ss)
